package com.ji.controller;

import com.ji.pojo.Department;
import com.ji.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class TestController {
    @Autowired
    private DepartmentService departmentService;
    @RequestMapping("/test")
    @ResponseBody
    public String test(){
        departmentService.addDepartment (new Department (101,"教学部"));
        return "ok";
    }
    @RequestMapping("/test1")
    @ResponseBody
    public String test1(){
        departmentService.updateDepartment(new Department (101,"体育部"));
        return "ok";
    }
    @RequestMapping("/test2")
    @ResponseBody
    public String test2(){
        Department department = departmentService.queryDepartment (101);
        System.out.println (department);
        return "ok";
    }
    @RequestMapping("/test3")
    @ResponseBody
    public String test3(){
        List<Department> departments = departmentService.queryAllDepartment ();
        for (Department department : departments) {
            System.out.println (department);
        }
        return "ok";
    }
    @RequestMapping("/test4")
    @ResponseBody
    public String test4(){
        departmentService.deleteDepartment(101);
        return "ok";
    }
}
